package com.shinbada.core.security.openapi;

import org.apache.commons.codec.digest.DigestUtils;

import java.security.MessageDigest;

/**
 * @author initcap
 * @date Created in 2020/10/20 14:41.
 */
public enum Signature {

    MD5 {
        @Override
        public String sign(byte[] payload) {
            return DigestUtils.md5Hex(payload);
        }

        @Override
        public MessageDigest getMessageDigest() {
            return DigestUtils.getMd5Digest();
        }
    },
    SHA256 {
        @Override
        public String sign(byte[] payload) {
            return DigestUtils.sha256Hex(payload);
        }

        @Override
        public MessageDigest getMessageDigest() {
            return DigestUtils.getSha256Digest();
        }
    };

    public abstract MessageDigest getMessageDigest();

    public abstract String sign(byte[] payload);

}
